const router = require('koa-router')()

router.prefix('/users')

const self = {
  username: 'kevin',
  password: '123456'
}

router.get('/', function (ctx, next) {
  ctx.body = 'this is a users response!'
})

router.get('/bar', function (ctx, next) {
  ctx.body = 'this is a users/bar response'
})

router.post('/login', async (ctx, next) => {
  const { username, password } = ctx.request.body
  if (username == self.username && password == self.password) {
    ctx.response.body = {
      code: 20000,
      success: true,
      data: {
        token: 'token'
      }
    }
  } else {
    ctx.response.body = {
      code: -1,
      success: false,
      errMsg: '账户错误, 请重新输入！'
    }
  }
})

module.exports = router
